<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>minMaxValue</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const minMaxValue = (value, min = -Infinity, max = Infinity) => Math.max(min, Math.min(value, max));
        const arr = [1, 2, 3, 4];
        const currentValue = 3;
        const currentIndex = arr.indexOf(currentValue);
        console.log(minMaxValue(currentIndex, 0, arr.length - 1)); // 2
    </script>
</body>

</html>